package info.javafans.cdn.web.action;

import info.javafans.cdn.dao.ActivityDao;
import info.javafans.cdn.dao.GroupDao;
import info.javafans.cdn.dao.NewsDao;
import info.javafans.cdn.domain.Activity;
import info.javafans.cdn.domain.Group;
import info.javafans.cdn.domain.News;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ShowIndexAction extends Action {

	@Override
	public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
		prepareDate(request, response);
		
		return "success";
	}
	
	/**
	 * 页面需要显示的数据
	 * prepareDate
	 */
	public static void prepareDate(HttpServletRequest request, HttpServletResponse response) {
		//读取头版新闻
		News frontNews = NewsDao.selectFrontNews();
		request.setAttribute("frontNews", frontNews);
		
		// 读取最新新闻
		List<News> newsList = NewsDao.getLatestNews();
		request.setAttribute("newsList", newsList);
		
		// 读取社团信息
		List<Group> groupList = GroupDao.selectActiveGroup();
		request.setAttribute("groupList", groupList);
		
		// 读取活动信息
		List<Activity> activityList = ActivityDao.selectLatestActivity();
		request.setAttribute("activityList", activityList);
	}

}
